package goleetcode

import "duan.com/leetcode/utils"
func buildTree(preorder []int, inorder []int) *utils.TreeNode {
    if len(preorder) == 0 {
        return nil
    }
    root := &utils.TreeNode{preorder[0], nil, nil}
    i := 0
    for ; i < len(inorder); i++ {
        if inorder[i] == preorder[0] {
            break
        }
    }
    root.Left = buildTree(preorder[1:len(inorder[:i])+1], inorder[:i])
    root.Right = buildTree(preorder[len(inorder[:i])+1:], inorder[i+1:])
    return root
}
